using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Xeml.Document;

namespace XemlInteractiveDesigner
{
    public partial class GermPlasmEditForm : Form
    {

        private IndividualsPool individualsPool;

        public IndividualsPool IndividualsPool
        {
            get { return individualsPool; }
            set { individualsPool = value; }
        }



        public GermPlasmEditForm(IndividualsPool ip)
        {

            InitializeComponent();
            if (ip == null)
                this.individualsPool = new IndividualsPool();
            else
            {
                this.individualsPool = ip;
                this.germPlasmEditCtrl.GermPlasmId = ip.GermPlasm;
                if (ip.Annotations.Contains("FreeText"))
                    this.germPlasmEditCtrl.FreeText = ip.Annotations.Find("FreeText").Annotation;
            }
            this.germPlasmEditCtrl.IndividualsPool = this.individualsPool;
        }

        private void germPlasmEditCtrl_Load(object sender, EventArgs e)
        {

        }

        private void buttonOk_Click(object sender, EventArgs e)
        {

            if (ValidateChildren())
            {

                this.individualsPool.NameSpace = "none";
                this.individualsPool.GermPlasm = germPlasmEditCtrl.GermPlasmId;

                if (String.IsNullOrEmpty(germPlasmEditCtrl.FreeText))
                    individualsPool.Annotations.Remove("FreeText");
                else
                {
                    if (individualsPool.Annotations.Contains("FreeText"))
                        this.individualsPool.Annotations.Find("FreeText").Annotation = germPlasmEditCtrl.FreeText;
                    else
                        this.individualsPool.Annotations.Add(new TaggedAnnotation("FreeText", germPlasmEditCtrl.FreeText));
                }
                // this.individualsPool. 
                //TODO: PoolSize management
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}